package com.jt9003.controller;



import com.jt9003.pojo.Query;
import com.jt9003.service.Documents_queryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class Documents_queryController {

    @Autowired
    private Documents_queryService documents_queryService;


    @RequestMapping("/getDocunmetlist")
    @ResponseBody
    public Object getDocunmetlist(@RequestParam(value = "p_name", required = false) String p_name,
                                  @RequestParam(value = "time", required = false) String time,
                                  @RequestParam(value = "registration_number", required = false) String registration_number){
        Map map =new HashMap();
        Map param =new HashMap();
        System.out.println(p_name+registration_number+time+"==============================");
        String s="";
        String end="";
        if (time!=null&&time!=""){
            String[] date=time.split(" - ");
            s=date[0];
            end=date[1];
        }
        param.put("registration_number",registration_number);
        param.put("p_name",p_name);
        param.put("s",s);
        param.put("end",end);
        try {
            List<Query> dcumentList = documents_queryService.getDocunmetlist(param);
            map.put("result", dcumentList);
            map.put("success", true);
            map.put("message", "查询患者列表成功");
            map.put("code", "0");
            map.put("", "");
        } catch (Exception e) {
            map.put("success", false);
            map.put("message", "查询患者列表失败");
        }
        return map;
    }





    @RequestMapping("/Documentscount")
    @ResponseBody
    public Object Documentscount(){
        Map map =new HashMap();
        try{
            int count  = documents_queryService.Documentscount();

            map.put("result", count);
            map.put("success", true);
            map.put("message", "查询列表总数成功");
        }catch (Exception e){
            map.put("success", false);
            map.put("message", "查询列表总数失败");
        }
        return map;
    }



    @RequestMapping("/getdailylist")
    public Object getdailylist(){
        Map map =new HashMap();
        try {
            List<Query> getdailylist = documents_queryService.getdailylist(map);
            map.put("data", getdailylist);
            map.put("success", true);
            map.put("message", "查询患者日结列表成功");
            map.put("code",0);
            map.put("count",0);
            map.put("", "");
        } catch (Exception e) {
            map.put("success", false);
            map.put("message", "查询患者日结列表失败");
        }
        return map;
    }





    @RequestMapping("/beforedailylist")
    public Object beforedailylist(String r_time){
        //没接收到
        System.out.println(r_time+"===============================================时间");

        Map map =new HashMap();
        try {
            List<Query> beforedailylist = documents_queryService.beforedailylist(r_time);
            map.put("data", beforedailylist);
            map.put("success", true);
            map.put("message", "根据日期查询患者列表成功");
            map.put("code",0);
            map.put("count",0);
            map.put("", "");
        } catch (Exception e) {
            map.put("success", false);
            map.put("message", "根据日期查询患者列表失败");
        }
        return map;
    }
}
